/**
 * Created by HREN_VAM.
 */
package net.receiving.converter;

import net.message.MessageType;
import net.message.Message;
import net.receiving.converter.factory.*;

import java.util.HashMap;

public class Generator {

    private HashMap<MessageType, MessageFactory> h;

    public Message getMessage(MessageType type, byte[] a) {
        return h.get(type).getMessage(a);
    }

    private static Generator ourInstance = new Generator();

    public static Generator getInstance() {
        return ourInstance;
    }

    private Generator() {
        h = new HashMap<MessageType, MessageFactory>();
        h.put(MessageType.ALIVE_MESSAGE, new AliveMessageFacory());
        h.put(MessageType.CREATE_IMAGE, new CreateImageMessageFacory());
        h.put(MessageType.GET_IMAGE_REQUEST, new GetImageRequestMessageFacory());
        h.put(MessageType.GET_IMAGE_RESPONSE, new GetImageResponseMessageFacory());
        h.put(MessageType.HELLO_REQUEST, new HelloRequestMessageFacory());
        h.put(MessageType.HELLO_RESPONSE, new HelloResponseMessageFacory());
        h.put(MessageType.JOIN_IMAGE_REQUEST, new JoinImageRequestMessageFacory());
        h.put(MessageType.JOIN_IMAGE_RESPONSE, new JoinImageResponseMessageFacory());
        h.put(MessageType.NEW_LINE, new NewLineMessageFacory());
    }
}
